<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/9 0009
 * Time: 9:55
 */
use think\Db;
function getNewSms($mobile,$content){

    $url="http://service.winic.org:8009/sys_port/gateway/index.asp";
    // $data = "id=%s&pwd=%s&to=%s&Content=%s&time=%s";
    $data = "id=%s&pwd=%s&to=%s&Content =%s&time=";
    $id = iconv("utf-8","gb2312","dahe1114");   //短信帐号
    $pwd = 'dahe0838';   //短信密码
    $to = $mobile;
    //$time = urlencode('2017/11/03 18:00:00');
    $content = urlencode(iconv("UTF-8","GB2312",$content));
    // $rdata = sprintf($data, $id, $pwd, $to, $content ,$time);
    $rdata = sprintf($data, $id, $pwd, $to, $content);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$rdata);
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $result = curl_exec($ch);
    $result = substr($result,0,3);
    return $result;
}
function getCode(){
    $randStr = str_shuffle('1234567890');
    $code = substr($randStr,0,4);
    return $code;
}
//点击加1
function addClick($id,$table){

    $res =Db::name($table)->where('id',$id)->setInc('click');
    return $res;
}

function getJson($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    return json_decode($output, true);
}

//获取域名前缀
function getDomainPrefix(){

    $domain = $_SERVER['HTTP_REFERER'];
    // $domain=  'http://jd.cjkp.com';
    $domain_arr = explode('.', $domain);
    $domain_prefix = $domain_arr[0];
    /* if(stripos($domain_prefix,"http://")!== false  || stripos("$domain_prefix","https://")!== false ){
         $ext = str_replace('http://','',$domain_prefix);
     }*/

    return $domain_prefix;
}

//获取公司信息
function getCompany(){
    $data =Db::name('company')->where('sign="pc"')->find();

    $data['service_code']=html_entity_decode($data['service_code']);
    return $data;
}
//栏目seo
function getColumnseo($column_id){
    $data =Db::name('seo')->where('column_id',$column_id)->where('sign="pc"')->find();
    return $data;
}

function getMonth($date){
    $where1 = 'is_del=0 and is_show=1 and sign="pc"';
    if($date){
        $max_year=date('Y',$date);
    }else{
        $sql_1 = 'SELECT FROM_UNIXTIME(ps_time,\'%Y\') nian  FROM `dh_works` where '.$where1.' GROUP BY nian ORDER BY nian DESC  LIMIT 1';
        $max_year =Db::name('works')->query($sql_1);
        $max_year =$max_year[0]['nian'];
    }

    $sql_2 ='SELECT CONCAT(FROM_UNIXTIME(ps_time,\'%Y\'),\'-\',FROM_UNIXTIME(ps_time,\'%m\'),\'-\',CEIL(FROM_UNIXTIME(ps_time,\'%d\')/7)) times FROM `dh_works` where '.$where1.' GROUP BY times';
    $year_month = Db::name('works')->query($sql_2);


    foreach ($year_month  as $k=>$v){
        $nian[]= explode('-',$v['times']);
    }
    foreach ($nian as $k=>$v){
        if(intval($v[0]) == intval($max_year)){
            $yue1[]=$v[1];
            $zhou[]=$v[2];
        }
    }
    $month= array('一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月');
    foreach ($month as $key =>$value){
        $month_2[$key][]=$value;
    }
    $week =array('第一周','第二周','第三周','第四周');
    foreach ($week as $key =>$value){
        $week_2[$key][]=$value;
    }

    foreach ($month_2 as $k=>$v){
        foreach ($yue1 as $value){
            if(intval($k+1)  == intval($value)){
                $month_2[$k]['class']='wxz';
            }
        }
    }

    foreach ($week_2 as $k=>$v){
        foreach ($zhou as $value){
            if(intval($k+1)  == intval($value)){
                $week_2[$k]['class']='wxz';
            }
        }
    }

    return $month_2;
}


    function googleTran($text){
     if(empty($text)) return "";
          sleep(1);//反间碟
     $wf=file_get_contents('http://translate.google.cn/translate_t?sl=zh-CN&tl=en&text='.urlencode($text).'#');
    if (false===$wf||empty($wf)){
            return false;
     }
     //截取相关信息
     $return = "";
    $wf=mb_substr($wf,14000,28100,'utf-8');
     $wf=strip_tags($wf);
     //print_r ($wf);
    $star=strpos($wf,"英语中文(简体)日语");
     if(false===$star){
          return false;
     }
    $end=strpos($wf,"Alpha字典");
     if(false===$end){
           return false;
    }
     $return = strip_tags(substr($wf,$star+18,$end-$star-18));

     return $return;

     }